package com.feiyu.controller;


import com.feiyu.pojo.PageBean;
import com.feiyu.service.EmpService;
import com.feiyu.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.net.InetAddress;
import java.time.LocalDate;

@Slf4j
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping("/emps")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       @Param("name") String name, @Param("gender") Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {


        PageBean pageBean = empService.page(page, pageSize, name, gender, start,end);

        log.info("分页查询-参数：{},{},{},{},{}"+page,pageSize,name,gender,start,end);
        return Result.success(pageBean);

    }


    /**
     *            批量删除员工
     */

 @DeleteMapping("/emps/{ids}")
    public Result deleteByIds( @PathVariable String[] ids){

   empService.deleteByIds(ids);

        return  Result.success();

    }
}
